package com.peak.distribution.entity.order;

import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import com.google.common.collect.Lists;
import com.peak.distribution.enums.Constants;
import com.peak.distribution.enums.PayType;
import com.peak.spring.boot.api.entity.LogicalDeleteEntity;

import lombok.Data;
import lombok.EqualsAndHashCode;

@Entity
@Table(name = "dis_order_pay_log")
@Data
@EqualsAndHashCode(callSuper=true)
public class DisOrderPayLog extends LogicalDeleteEntity {

	private static final long serialVersionUID = Constants.DISTRIBUTION_VERSION;
	
	/** 支付号 */
	private String payNo;

	/** 类型 */
	private PayType type;

	/** 交易渠道 */
	private String channel;

	/** 交易方式 */
	private Integer method;

	/** 交易金额 */
	private Integer amount;

	/** 手续费 */
	private Integer fee;

	/** 交易日期 */
	private Date time;

	/** 交易码 */
	private String code;

	/** 交易用户名 */
	private String tradeUsername;

	/** 交易号 */
	private String tradeNo;

	/** 同步通知状态 */
	private String syncStatus;

	/** 异步通知状态 */
	private String asyncStatus;

	/** 订单 */
	private List<DisOrder> orders = Lists.newArrayList();

	@Enumerated(EnumType.STRING)
	public PayType getType() {
		return type;
	}

	@OneToMany(mappedBy = "payLog")
	@Fetch(FetchMode.SELECT)
	@LazyCollection(LazyCollectionOption.TRUE)
	public List<DisOrder> getOrders() {
		return orders;
	}
}
